package com.jmpt.fangbohui.adapter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jmpt.fangbohui.R;
import com.jmpt.fangbohui.bean.NewHouseBean;
import com.jmpt.fangbohui.utils.ImageLoaderHelper;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;

public class NewHouseListAdapter extends BaseAdapter {
	
	private Context mContext;
	public List<NewHouseBean> houseList = new ArrayList<NewHouseBean>();

    public NewHouseListAdapter(Context context) {
    	this.mContext = context;
    }
	@Override
	public int getCount() {
		return houseList.size();
	}

	@Override
	public Object getItem(int position) {
		return houseList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return houseList.get(position).id;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = View.inflate(mContext, R.layout.item_list_newhouse, null);
        }
        Holder holder = getHolder(convertView);
        NewHouseBean bean = houseList.get(position);
        ImageLoaderHelper.displayImage(bean.pic, holder.housePhoto);
        holder.houseTitle.setText(bean.title);
        holder.houseZone.setText(bean.zonename);
        holder.housePrice.setText(String.valueOf(bean.j_price + "元/平"));
        holder.houseAddress.setText(bean.addr);
        holder.tel.setText("电话：" + bean.tel);
        
        return convertView;

    }

    private Holder getHolder(final View view) {
        Holder holder = (Holder) view.getTag();
        if (holder == null) {
            holder = new Holder(view);
            view.setTag(holder);
        }
        return holder;
    }


    private class Holder {
        public ImageView housePhoto;
        public TextView houseTitle;
        public TextView houseZone;
        public TextView housePrice;
        public TextView houseAddress;
        public TextView tel;
        public Holder(View view) {
        	housePhoto = (ImageView) view.findViewById(R.id.iv_newhouse_item_photo);
        	houseTitle = (TextView) view.findViewById(R.id.tv_newhouse_item_title);
        	houseZone = (TextView) view.findViewById(R.id.tv_newhouse_item_zone);
        	housePrice = (TextView) view.findViewById(R.id.tv_newhouse_item_price);
        	houseAddress = (TextView) view.findViewById(R.id.tv_newhouse_item_addr);
        	tel = (TextView) view.findViewById(R.id.tv_newhouse_item_tel);
        }
    }
    
}
